<template>
  <div class="wm1080px y wn jc">
    <top @topEvent="topEvent" />
    <!-- <banner v-if="banners.length" :fdata="banners" /> -->
    <itemsList :fdata="items" />
    <footer1 />
  </div>
</template>

<script>
import top from "../../components/top";
import banner from "../../components/admin/banner";
import itemsList from "../../components/index/itemsList";
import footer1 from "../../components/footer";
export default {
  components: { top, banner, itemsList, footer1 },
  watch: {
    "$route.params.id"(a) {
      this.ChangeParams(a);
    }
  },
  data() {
    return {
      banners: {},
      items: {}
    };
  },
  computed: {},
  created() {
    const data = { cmd: 0, val: {} };
    if (!sessionStorage.g4 || sessionStorage.g4 == undefined) {
      this.getData({ cmd: 1005 });
    }
    this.ChangeParams(this.$route.params.id);
  },
  methods: {
    ChangeParams(a) {
      if (Number(a).toString() == a) {
        if (Number(a)) {
          this.getData({
            cmd: 0,
            val: { table: "items", itemType: Number(a) }
          });
        } else {
          this.getData({ cmd: 2001 });
        }
      } else {
        let tmp = decodeURIComponent(a).parse();
        console.log(tmp);
      }
    },
    topEvent(a) {
      // this.show = 0;
      // this.total = -1;
      // if (a.substr(0, 1) == "/") {
      //   this.getData();
      //   this.$router.push(a);
      // } else if (Number(a) == a)
      //   this.getData({ val: { itemType: a, weight: 1 } });
      // else if (a == "search") {
      //   this.searchShow = true;
      //   // console.log(this.$cp(this.list));
      // }
    },
    getData(val) {
      this.$axios
        .post("q.php", val)
        .then(r => {
          const data = r.data;
          switch (val.cmd) {
            case 2001:
              this.banners = data.banner;
              this.items = data.data;
              // console.log(this.$cp(data.data));
              break;
            case 1005:
              sessionStorage.setItem("g4", JSON.stringify(data));
              break;
            default:
              const ret = [
                {
                  name: "我的搜索",
                  info: "一共为您搜索到 " + data.result.length + "条数据",
                  data: data.result
                }
              ];
              if (val.val.itemType) {
                ret[0] = JSON.parse(sessionStorage.g4).itemType.v2item(
                  val.val.itemType
                );
                ret[0].data = data.result;
              }
              this.items = ret;
              break;
          }
        })
        .catch(err => {
          // console.log(err);
        });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
